<?php

namespace app\api\controller;

use addons\epay\library\Service;
use app\admin\model\goods\Order;
use app\common\controller\Api;
use app\common\controller\Payment;
use think\Controller;
use think\Db;
use think\Request;


class Wanlshopshop extends Api
{
    private static $model;
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = '*';


    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        self::$model = new \app\common\model\WanlshopShop();
    }

    /**
     * 店铺列表
     */
    public function lists()
    {

        $pageSize = input('pagesize', 15);

        $where = [
            'status' => 'normal',
        ];
        $isScore = input('is_score');
        if ($isScore) {
            $where['is_score'] = 1;
        }

        $list = self::$model->where($where)->order('updatetime desc')->paginate($pageSize);

        $this->success('商品列表', $list);
    }

    /**
     * 店铺详情
     */
    public function read()
    {
        $id = input('id');
        $row_info = self::$model->find($id);
//        if ($row_info->status != 'normal') {
//            $this->error('该商品暂无法购买！');
//        }
        $lon = input('lon');
        $lat = input('lat');

        $distance = get_distance($lat, $lon, $row_info->lat, $row_info->lng);
        if ($distance > 1000) {
            $distance = round($distance * 0.001, 1) . 'km';
        } else {
            $distance .= 'm';
        }

        $row_info->distance = $distance;
        $this->success('店铺详情', $row_info);
    }
}
